/**
 * Created by yunpeng on 2014/12/4.
 */
var Table = require('../utils/Table').Table;

var Count = function(date, state1, state2, state3) {
    this.date = date;
    this.state1 = state1;
    this.state2 = state2;
    this.state3 = state3;
    if (typeof this.save != 'function') {//仅在第一次调用的初始化
        Count.prototype.save = function(callback){
            new Table('count').insert(this,function(err){
                if(err){
                    callback(false);
                }else{
                    callback(true);
                }
            });
        };
    }
    if (typeof this.getCountList!='function'){
        Count.prototype.getCountList = function(params,page,callback){
            var columns = " l.id,DATE_FORMAT(l.date,'%Y-%m-%d') as date,l.state1,l.state2,l.state3 ";
            var condition1 =' ';
            if(params[0]&&params[0]!='null'){//开始时间
                condition1+=" AND l.createtime>'"+params[0]+"'";
            }
            if(params[1]&&params[1]!='null'){//结束时间
                condition1+=" AND l.createtime<'"+params[1]+"'";
            }

            new Table(' count l ').queryPage(columns,condition1,page,function(err,result){
                //console.log(result);
                callback(result);
            });
        }

    }
}
exports.Count = Count;